﻿using IDAL;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class D_Customer : ICustomer
    {
        public void Add(Customer item)
        {
            CakeEntities db = new CakeEntities();
            db.Customer.Add(item);
            db.SaveChanges();
        }

        public void Delete(int id)
        {
            CakeEntities db = new CakeEntities();
            db.Customer.Remove(db.Customer.Find(id));
            db.SaveChanges();
        }

        public Customer FindById(int id)
        {
            CakeEntities db = new CakeEntities();
            return db.Customer.Find(id);
        }

        public List<Customer> GetAll()
        {
            CakeEntities db = new CakeEntities();
            return db.Customer.ToList();
        }

        public void Updata(int id, Customer item)
        {
            CakeEntities db = new CakeEntities();
            var data=db.Customer.Find(id);
            if (data!=null)
            {
                data.CustomerName = item.CustomerName;
                data.Password = item.Password;
                data.Email= item.Email;
                data.CName= item.CName;
                data.Areas = item.Areas;
                data.QQ = item.QQ;
                data.Avatar = item.Avatar;
                data.Gender = item.Gender;
                data.Birthday = item.Birthday;
                db.SaveChanges();
            }
        }
    }
}
